package leetcode.每日一题;

import org.junit.Test;

/**
 * @author :songyaozhang
 * @date :Created 2021/8/18 9:35
 * @description :https://leetcode-cn.com/problems/student-attendance-record-ii/
 */
public class 学生出勤记录II {
    @Test
    public void test() {
        Solution solution = new Solution();
        System.out.println(solution.checkRecord(10101));
    }

    class Solution {
        int res = 0;

        public int checkRecord(int n) {
            backtrack(0, new int[3], n);
            return res;
        }

        private void backtrack(int index, int[] count, int n) {
            if (index == n) {
                res++;
                return;
            }
            for (int i = 0; i < 3; i++) {
                count[i]++;
                if (count[0] < 2 && count[1] < 3) {
                    backtrack(index + 1, count, n);
                }
                count[i]--;
            }
        }
    }
}
